home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume29 / zsh2.2 / part14 < prev    next >
Encoding:
Text File  |  1992-05-13  |  49.0 KB  |  2,317 lines

  1. Newsgroups: comp.sources.misc
  2. From: pfalstad@phoenix.Princeton.EDU (Paul Falstad)
  3. Subject:  v29i110:  zsh2.2 - The Z shell, Part14/17
  4. Message-ID: <1992May13.160936.11005@sparky.imd.sterling.com>
  5. X-Md4-Signature: d9e717f9307ae05be74057c71501ab4c
  6. Date: Wed, 13 May 1992 16:09:36 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: pfalstad@phoenix.Princeton.EDU (Paul Falstad)
  10. Posting-number: Volume 29, Issue 110
  11. Archive-name: zsh2.2/part14
  12. Environment: BSD
  13. Supersedes: zsh2.1: Volume 24, Issue 1-19
  14.  
  15. #!/bin/sh
  16. # this is aa.14 (part 14 of zsh2.2)
  17. # do not concatenate these parts, unpack them in order with /bin/sh
  18. # file zsh2.2/src/zle_refresh.c continued
  19. #
  20. if test ! -r _shar_seq_.tmp; then
  21.     echo 'Please unpack part 1 first!'
  22.     exit 1
  23. fi
  24. (read Scheck
  25.  if test "$Scheck" != 14; then
  26.     echo Please unpack part "$Scheck" next!
  27.     exit 1
  28.  else
  29.     exit 0
  30.  fi
  31. ) < _shar_seq_.tmp || exit 1
  32. if test ! -f _shar_wnt_.tmp; then
  33.     echo 'x - still skipping zsh2.2/src/zle_refresh.c'
  34. else
  35. echo 'x - continuing file zsh2.2/src/zle_refresh.c'
  36. sed 's/^X//' << 'SHAR_EOF' >> 'zsh2.2/src/zle_refresh.c' &&
  37. X    return ct;
  38. X}
  39. X
  40. SHAR_EOF
  41. echo 'File zsh2.2/src/zle_refresh.c is complete' &&
  42. chmod 0644 zsh2.2/src/zle_refresh.c ||
  43. echo 'restore of zsh2.2/src/zle_refresh.c failed'
  44. Wc_c="`wc -c < 'zsh2.2/src/zle_refresh.c'`"
  45. test 12058 -eq "$Wc_c" ||
  46.     echo 'zsh2.2/src/zle_refresh.c: original size 12058, current size' "$Wc_c"
  47. rm -f _shar_wnt_.tmp
  48. fi
  49. # ============= zsh2.2/src/zle_utils.c ==============
  50. if test -f 'zsh2.2/src/zle_utils.c' -a X"$1" != X"-c"; then
  51.     echo 'x - skipping zsh2.2/src/zle_utils.c (File already exists)'
  52.     rm -f _shar_wnt_.tmp
  53. else
  54. > _shar_wnt_.tmp
  55. echo 'x - extracting zsh2.2/src/zle_utils.c (Text)'
  56. sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/src/zle_utils.c' &&
  57. X/*
  58. X *
  59. X * zle_utils.c - miscellaneous line editor utilities
  60. X *
  61. X * This file is part of zsh, the Z shell.
  62. X *
  63. X * This software is Copyright 1992 by Paul Falstad
  64. X *
  65. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  66. X * use this software as long as: there is no monetary profit gained
  67. X * specifically from the use or reproduction of this software, it is not
  68. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  69. X * included prominently in any copy made. 
  70. X *
  71. X * The author make no claims as to the fitness or correctness of this software
  72. X * for any use whatsoever, and it is provided as is. Any use of this software
  73. X * is at the user's own risk. 
  74. X *
  75. X */
  76. X
  77. X#define ZLE
  78. X#include "zsh.h"
  79. X
  80. X/* make sure that the line buffer has at least sz chars */
  81. X
  82. Xvoid sizeline(sz) /**/
  83. Xint sz;
  84. X{
  85. X    while (sz > linesz)
  86. X        line = (unsigned char *)realloc(line,(linesz *= 4)+1);
  87. X}
  88. X
  89. X/* insert space for ct chars at cursor position */
  90. X
  91. Xvoid spaceinline(ct) /**/
  92. Xint ct;
  93. X{
  94. Xint i;
  95. X
  96. X    while (ct+ll > linesz)
  97. X        line = (unsigned char *)realloc(line,(linesz *= 4)+1);
  98. X    for (i = ll; i >= cs; i--)
  99. X        line[i+ct] = line[i];
  100. X    ll += ct;
  101. X    line[ll] = '\0';
  102. X}
  103. X
  104. Xvoid backkill(ct,dir) /**/
  105. Xint ct;int dir;
  106. X{
  107. Xint i = (cs -= ct);
  108. X
  109. X    cut(i,ct,dir);
  110. X    while (line[i] = line[i+ct])
  111. X        i++;
  112. X    ll -= ct;
  113. X}
  114. X
  115. Xvoid forekill(ct,dir) /**/
  116. Xint ct;int dir;
  117. X{
  118. Xint i = cs;
  119. X
  120. X    cut(i,ct,dir);
  121. X    while (line[i] = line[i+ct])
  122. X        i++;
  123. X    ll -= ct;
  124. X}
  125. X
  126. Xvoid cut(i,ct,dir) /**/
  127. Xint i;int ct;int dir;
  128. X{
  129. X    if (vibufspec) {
  130. X        int owrite = 1;
  131. X        if (vibufspec >= 'A' && vibufspec <= 'Z') {
  132. X            owrite = 0; vibufspec = tolower(vibufspec);
  133. X        }
  134. X        vibufspec += (idigit(vibufspec)) ? - '1' +26 : - 'a';
  135. X        if (owrite || !vibuf[vibufspec]) {
  136. X            if (vibuf[vibufspec]) free(vibuf[vibufspec]);
  137. X            vibuf[vibufspec] = zalloc(ct+1);
  138. X            ztrncpy(vibuf[vibufspec],line+i,ct);
  139. X        } else {
  140. X            int len = strlen(vibuf[vibufspec]);
  141. X            vibuf[vibufspec] = realloc(vibuf[vibufspec],ct+len);
  142. X            ztrncpy(vibuf[vibufspec]+len,line+i,ct);
  143. X        }
  144. X        vibufspec = 0;
  145. X        return;
  146. X    }
  147. X    if (!cutbuf)
  148. X        cutbuf = ztrdup("");
  149. X    else if (!(lastcmd & ZLE_KILL)) {
  150. X        kringnum = (kringnum+1)&(KRINGCT-1);
  151. X        if (kring[kringnum])
  152. X            free(kring[kringnum]);
  153. X        kring[kringnum] = cutbuf;
  154. X        cutbuf = ztrdup("");
  155. X    }
  156. X    if (dir) {
  157. X        char *s = zalloc(strlen(cutbuf)+ct+1);
  158. X        strncpy(s,(char *) line+i,ct);
  159. X        strcpy(s+ct,cutbuf);
  160. X        free(cutbuf);
  161. X        cutbuf = s;
  162. X    } else {
  163. X        int x;
  164. X
  165. X        cutbuf = realloc(cutbuf,(x = strlen(cutbuf))+ct+1);
  166. X        ztrncpy(cutbuf+x,line+i,ct);
  167. X    }
  168. X}
  169. X
  170. Xvoid backdel(ct) /**/
  171. Xint ct;
  172. X{
  173. Xint i = (cs -= ct);
  174. X
  175. X    while (line[i] = line[i+ct])
  176. X        i++;
  177. X    ll -= ct;
  178. X}
  179. X
  180. Xvoid foredel(ct) /**/
  181. Xint ct;
  182. X{
  183. Xint i = cs;
  184. X
  185. X    while (line[i] = line[i+ct])
  186. X        i++;
  187. X    ll -= ct;
  188. X}
  189. X
  190. Xvoid setline(s) /**/
  191. Xchar *s;
  192. X{
  193. X    sizeline(strlen(s));
  194. X    strcpy((char *) line,s);
  195. X    cs = ll = strlen(s);
  196. X    if (cs && bindtab == altbindtab) cs--;
  197. X}
  198. X
  199. Xvoid sethistline(s) /**/
  200. Xunsigned char *s;
  201. X{
  202. X    setline(s);
  203. X    for (s = line; *s; s++)
  204. X        if (*s == (unsigned char)HISTSPACE)
  205. X            *s = ' ';
  206. X}
  207. X
  208. Xint findbol() /**/
  209. X{
  210. Xint x = cs;
  211. X
  212. X    while (x > 0 && line[x-1] != '\n') x--;
  213. X    return x;
  214. X}
  215. X
  216. Xint findeol() /**/
  217. X{
  218. Xint x = cs;
  219. X
  220. X    while (x != ll && line[x] != '\n') x++;
  221. X    return x;
  222. X}
  223. X
  224. Xvoid findline(a,b) /**/
  225. Xint *a;int *b;
  226. X{
  227. X    *a = findbol();
  228. X    *b = findeol();
  229. X}
  230. X
  231. Xstatic int lastlinelen;
  232. X
  233. Xvoid initundo() /**/
  234. X{
  235. Xint t0;
  236. X
  237. X    for (t0 = 0; t0 != UNDOCT; t0++)
  238. X        undos[t0].change = NULL;
  239. X    undoct = 0;
  240. X    lastline = zalloc(lastlinelen = (ll+1 < 32) ? 32 : ll+1);
  241. X    strcpy((char *) lastline,(char *) line);
  242. X    lastcs = cs;
  243. X}
  244. X
  245. Xvoid addundo() /**/
  246. X{
  247. Xint pf,sf;
  248. Xunsigned char *s,*s2,*t,*t2;
  249. Xstruct undoent *ue;
  250. X
  251. X    for (s = line, t = lastline; *s && *s==*t; s++,t++);
  252. X    if (!*s && !*t)
  253. X        return;
  254. X    pf = s-line;
  255. X    for (s2 = (unsigned char *)line+strlen((char *) line),
  256. X            t2 = lastline+strlen((char *) lastline);
  257. X        s2 > s && t > t2 && s2[-1] == t2[-1]; s2--,t2--);
  258. X    sf = strlen((char *) s2);
  259. X    ue = undos+(undoct = (UNDOCT-1) & (undoct+1));
  260. X    ue->pref = pf;
  261. X    ue->suff = sf;
  262. X    ue->len = t2-t;
  263. X    ue->cs = lastcs;
  264. X    strncpy(ue->change = halloc(ue->len),(char *) t,ue->len);
  265. X    while (ll+1 > lastlinelen)
  266. X        {
  267. X        free(lastline);
  268. X        lastline = zalloc(lastlinelen *= 2);
  269. X        }
  270. X    strcpy((char *) lastline,(char *) line);
  271. X    lastcs = cs;
  272. X}
  273. X
  274. Xvoid freeundo() /**/
  275. X{
  276. X    free(lastline);
  277. X}
  278. X
  279. Xint hstrncmp(s,t,len) /**/
  280. Xchar *s;char *t;int len;
  281. X{
  282. X    while (len && *s && (*s == *t || (*s == ' ' && *t == HISTSPACE) ||
  283. X            (*s == HISTSPACE && *t == ' ')))
  284. X        s++,t++,len--;
  285. X    return len;
  286. X}
  287. X
  288. Xint hstrcmp(s,t) /**/
  289. Xchar *s;char *t;
  290. X{
  291. X    while (*s && (*s == *t || (*s == ' ' && *t == HISTSPACE) ||
  292. X            (*s == HISTSPACE && *t == ' ')))
  293. X        s++,t++;
  294. X    return !(*s == '\0' && *t == '\0');
  295. X}
  296. X
  297. Xchar *hstrnstr(s,t,len) /**/
  298. Xchar *s;char *t;int len;
  299. X{
  300. X    for (; *s; s++)
  301. X        if (!hstrncmp(t,s,len))
  302. X            return s;
  303. X    return NULL;
  304. X}
  305. X
  306. SHAR_EOF
  307. chmod 0644 zsh2.2/src/zle_utils.c ||
  308. echo 'restore of zsh2.2/src/zle_utils.c failed'
  309. Wc_c="`wc -c < 'zsh2.2/src/zle_utils.c'`"
  310. test 4690 -eq "$Wc_c" ||
  311.     echo 'zsh2.2/src/zle_utils.c: original size 4690, current size' "$Wc_c"
  312. rm -f _shar_wnt_.tmp
  313. fi
  314. # ============= zsh2.2/src/zsh.h ==============
  315. if test -f 'zsh2.2/src/zsh.h' -a X"$1" != X"-c"; then
  316.     echo 'x - skipping zsh2.2/src/zsh.h (File already exists)'
  317.     rm -f _shar_wnt_.tmp
  318. else
  319. > _shar_wnt_.tmp
  320. echo 'x - extracting zsh2.2/src/zsh.h (Text)'
  321. sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/src/zsh.h' &&
  322. X/*
  323. X *
  324. X * zsh.h - standard header file
  325. X *
  326. X * This file is part of zsh, the Z shell.
  327. X *
  328. X * This software is Copyright 1992 by Paul Falstad
  329. X *
  330. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  331. X * use this software as long as: there is no monetary profit gained
  332. X * specifically from the use or reproduction of this software, it is not
  333. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  334. X * included prominently in any copy made. 
  335. X *
  336. X * The author make no claims as to the fitness or correctness of this software
  337. X * for any use whatsoever, and it is provided as is. Any use of this software
  338. X * is at the user's own risk. 
  339. X *
  340. X */
  341. X
  342. X#include "config.h"
  343. X
  344. X#include <stdio.h>
  345. X#include <ctype.h>
  346. X
  347. X#ifdef HAS_STRING
  348. X#include <string.h>
  349. X#else
  350. X#include <strings.h>
  351. X#endif
  352. X
  353. X#ifdef HAS_LOCALE
  354. X#include <locale.h>
  355. X#endif
  356. X
  357. X#ifdef HAS_STDLIB
  358. X#include <stdlib.h>
  359. X#endif
  360. X
  361. X#ifdef SYSV
  362. X#include <sys/bsdtypes.h>
  363. X#define _POSIX_SOURCE
  364. X#include <sys/limits.h>
  365. X#include <sys/sioctl.h>
  366. X#define MAXPATHLEN PATH_MAX
  367. X#define lstat stat
  368. Xextern int gethostname();
  369. X#define sigmask(m) m
  370. X#include <sys/dirent.h>
  371. X#else
  372. X#include <sys/types.h>        /* this is the key to the whole thing */
  373. X#endif
  374. X
  375. X#ifdef _IBMR2
  376. X#undef _BSD   /* union wait SUCKS! */
  377. X#include <sys/wait.h>
  378. X#define _BSD
  379. X#else
  380. X#include <sys/wait.h>
  381. X#endif
  382. X
  383. X#include <sys/time.h>
  384. X
  385. X#ifndef SYSV
  386. X#include <sys/resource.h>
  387. X#endif
  388. X
  389. X#include <sys/file.h>
  390. X#include <signal.h>
  391. X
  392. X#ifdef TERMIO
  393. X#define VDISABLEVAL -1
  394. X#define TIO 1
  395. X#include <sys/termio.h>
  396. X#else
  397. X#ifdef TERMIOS
  398. X#define VDISABLEVAL 0
  399. X#define TIO 1
  400. X#include <termios.h>
  401. X#else
  402. X#include <sgtty.h>
  403. X#endif
  404. X#endif
  405. X
  406. X#ifdef SYSV
  407. X#undef TIOCGWINSZ
  408. X#endif
  409. X
  410. X#include <sys/param.h>
  411. X#include <sys/times.h>
  412. X
  413. X#ifdef SYSV
  414. X#undef _POSIX_SOURCE
  415. X#endif
  416. X
  417. X#ifdef __hp9000s800
  418. X#include <sys/bsdtty.h>
  419. X#endif
  420. X
  421. X#ifndef sun
  422. X#include <sys/ioctl.h>
  423. X#else
  424. X#include <sys/filio.h>
  425. X#endif
  426. X
  427. X#define VERSIONSTR "zsh v2.2.0"
  428. X
  429. X#if 0 /* __STDC__ */
  430. X#include <unistd.h>
  431. X#include <fcntl.h>
  432. X#include <stat.h>
  433. X#define DCLPROTO(X) X
  434. X#undef NULL
  435. X#define NULL ((void *)0)
  436. X#else /* not __STDC__ */
  437. X#include <sys/stat.h>
  438. X#define DCLPROTO(X) ()
  439. X#ifndef NULL
  440. X#define NULL 0
  441. X#endif
  442. X#endif /* __STDC__ */
  443. X
  444. X#ifdef QDEBUG
  445. X#define DCLPROTO(X) X
  446. X#endif
  447. X
  448. X#define DEFWORDCHARS "*?_-.[]~=/&;!#$%^(){}<>"
  449. X#define DEFTIMEFMT "%E real  %U user  %S system  %P %J"
  450. X#ifdef UTMP_HOST
  451. X#define DEFWATCHFMT "%n has %a %l from %m."
  452. X#else
  453. X#define DEFWATCHFMT "%n has %a %l."
  454. X#endif
  455. X
  456. X#ifdef GLOBALS
  457. X#define EXTERN
  458. X#else
  459. X#define EXTERN extern
  460. X#endif
  461. X
  462. X#ifdef HAS_STRING
  463. X#define killpg(pgrp,sig) kill(-(pgrp),sig)
  464. X#endif
  465. X
  466. X#ifndef F_OK
  467. X#define F_OK 00
  468. X#define R_OK 04
  469. X#define W_OK 02
  470. X#define X_OK 01
  471. X#endif
  472. X
  473. X#include "zle.h"
  474. X
  475. X/* size of job list */
  476. X
  477. X#define MAXJOB 80
  478. X
  479. X/* memory allocation routines - changed with permalloc()/heapalloc() */
  480. X
  481. Xvptr (*alloc)DCLPROTO((int));
  482. Xvptr (*ncalloc)DCLPROTO((int));
  483. X
  484. X#define addhnode(A,B,C,D) Addhnode(A,B,C,D,1)
  485. X#define addhperm(A,B,C,D) Addhnode(A,B,C,D,0)
  486. X
  487. X/* character tokens */
  488. X
  489. X#define ALPOP            ((char) 0x81)
  490. X#define HISTSPACE        ((char) 0x83)
  491. X#define Pound            ((char) 0x84)
  492. X#define String            ((char) 0x85)
  493. X#define Hat                ((char) 0x86)
  494. X#define Star            ((char) 0x87)
  495. X#define Inpar            ((char) 0x88)
  496. X#define Outpar            ((char) 0x89)
  497. X#define Qstring        ((char) 0x8a)
  498. X#define Equals            ((char) 0x8b)
  499. X#define Bar                ((char) 0x8c)
  500. X#define Inbrace        ((char) 0x8d)
  501. X#define Outbrace        ((char) 0x8e)
  502. X#define Inbrack        ((char) 0x8f)
  503. X#define Outbrack        ((char) 0x90)
  504. X#define Tick            ((char) 0x91)
  505. X#define Inang            ((char) 0x92)
  506. X#define Outang            ((char) 0x93)
  507. X#define Quest            ((char) 0x94)
  508. X#define Tilde            ((char) 0x95)
  509. X#define Qtick            ((char) 0x96)
  510. X#define Comma            ((char) 0x97)
  511. X#define Nularg            ((char) 0x98)
  512. X
  513. X/* chars that need to be quoted if meant literally */
  514. X
  515. X#define SPECCHARS "#$^*()$=|{}[]`<>?~;&!\n\t \\\'\""
  516. X
  517. X/* ALPOP in the form of a string */
  518. X
  519. X#define ALPOPS " \201"
  520. X#define HISTMARK "\201"
  521. X
  522. X#define SEPER 1
  523. X#define NEWLIN 2
  524. X#define LEXERR 3
  525. X#define SEMI 4
  526. X#define DSEMI 5
  527. X#define AMPER 6
  528. X#define INPAR 7
  529. X#define INBRACE 8
  530. X#define OUTPAR 9
  531. X#define DBAR 10
  532. X#define DAMPER 11
  533. X#define BANG 12
  534. X#define OUTBRACE 13
  535. X#define OUTANG 14
  536. X#define OUTANGBANG 15
  537. X#define DOUTANG 16
  538. X#define DOUTANGBANG 17
  539. X#define INANG 18
  540. X#define DINANG 19
  541. X#define DINANGDASH 20
  542. X#define INANGAMP 21
  543. X#define OUTANGAMP 22
  544. X#define OUTANGAMPBANG 23
  545. X#define DOUTANGAMP 24
  546. X#define DOUTANGAMPBANG 25
  547. X#define TRINANG 26
  548. X#define BAR 27
  549. X#define BARAMP 28
  550. X#define DINBRACK 29
  551. X#define DOUTBRACK 30
  552. X#define STRING 31
  553. X#define ENVSTRING 32
  554. X#define ENVARRAY 33
  555. X#define ENDINPUT 34
  556. X#define INOUTPAR 35
  557. X#define DO 36
  558. X#define DONE 37
  559. X#define ESAC 38
  560. X#define THEN 39
  561. X#define ELIF 40
  562. X#define ELSE 41
  563. X#define FI 42
  564. X#define FOR 43
  565. X#define CASE 44
  566. X#define IF 45
  567. X#define WHILE 46
  568. X#define FUNC 47
  569. X#define REPEAT 48
  570. X#define TIME 49
  571. X#define UNTIL 50
  572. X#define EXEC 51
  573. X#define COMMAND 52
  574. X#define SELECT 53
  575. X#define COPROC 54
  576. X#define NOGLOB 55
  577. X#define DASH 56
  578. X#define NOCORRECT 57
  579. X#define FOREACH 58
  580. X#define ZEND 59
  581. X
  582. X#define WRITE 0
  583. X#define WRITENOW 1
  584. X#define APP 2
  585. X#define APPNOW 3
  586. X#define MERGEOUT 4
  587. X#define MERGEOUTNOW 5
  588. X#define ERRAPP 6
  589. X#define ERRAPPNOW 7
  590. X#define READ 8
  591. X#define HEREDOC 9
  592. X#define HEREDOCDASH 10
  593. X#define HERESTR 11
  594. X#define MERGE 12
  595. X#define CLOSE 13
  596. X#define INPIPE 14
  597. X#define OUTPIPE 15
  598. X#define NONE 16
  599. X
  600. X#ifdef GLOBALS
  601. Xint redirtab[TRINANG-OUTANG+1] = {
  602. X    WRITE,
  603. X    WRITENOW,
  604. X    APP,
  605. X    APPNOW,
  606. X    READ,
  607. X    HEREDOC,
  608. X    HEREDOCDASH,
  609. X    MERGE,
  610. X    MERGEOUT,
  611. X    MERGEOUTNOW,
  612. X    ERRAPP,
  613. X    ERRAPPNOW,
  614. X    HERESTR,
  615. X};
  616. X#else
  617. Xint redirtab[TRINANG-OUTANG+1];
  618. X#endif
  619. X
  620. X#define IS_READFD(X) ((X)>=READ && (X)<=MERGE)
  621. X#define IS_REDIROP(X) ((X)>=OUTANG && (X)<=TRINANG)
  622. X#define IS_ERROR_REDIR(X) ((X)>=MERGEOUT && (X)<=ERRAPPNOW)
  623. X#define UN_ERROR_REDIR(X) ((X)-MERGEOUT+WRITE)
  624. X
  625. X#define FD_WORD   -1
  626. X#define FD_COPROC -2
  627. X#define FD_CLOSE  -3
  628. X
  629. XEXTERN char **environ;
  630. X
  631. Xtypedef struct hashtab *Hashtab;
  632. Xtypedef struct hashnode *Hashnode;
  633. Xtypedef struct schedcmd *Schedcmd;
  634. Xtypedef struct alias *Alias;
  635. Xtypedef struct process *Process;
  636. Xtypedef struct job *Job;
  637. Xtypedef struct value *Value;
  638. Xtypedef struct arrind *Arrind;
  639. Xtypedef struct varasg *Varasg;
  640. Xtypedef struct param *Param;
  641. Xtypedef struct cmdnam *Cmdnam;
  642. Xtypedef struct cond *Cond;
  643. Xtypedef struct cmd *Cmd;
  644. Xtypedef struct pline *Pline;
  645. Xtypedef struct sublist *Sublist;
  646. Xtypedef struct list *List;
  647. Xtypedef struct lklist *Lklist;
  648. Xtypedef struct lknode *Lknode;
  649. Xtypedef struct comp *Comp;
  650. Xtypedef struct redir *Redir;
  651. Xtypedef struct complist *Complist;
  652. Xtypedef struct heap *Heap;
  653. Xtypedef struct histent *Histent;
  654. Xtypedef struct hp *Hp;
  655. Xtypedef struct compctl *Compctl;
  656. Xtypedef void (*FFunc)DCLPROTO((vptr));
  657. Xtypedef vptr (*VFunc)DCLPROTO((vptr));
  658. Xtypedef void (*HFunc)DCLPROTO((char *,char *));
  659. X
  660. X/* linked list abstract data type */
  661. X
  662. Xstruct lknode;
  663. Xstruct lklist;
  664. X
  665. Xstruct lknode {
  666. X   Lknode next,last;
  667. X   vptr dat;
  668. X   };
  669. Xstruct lklist {
  670. X   Lknode first,last;
  671. X   };
  672. X
  673. X#define addnode(X,Y) insnode(X,(X)->last,Y)
  674. X#define full(X) ((X)->first != NULL)
  675. X#define firstnode(X) ((X)->first)
  676. X#define getaddrdata(X) (&((X)->dat))
  677. X#define getdata(X) ((X)->dat)
  678. X#define setdata(X,Y) ((X)->dat = (Y))
  679. X#define lastnode(X) ((X)->last)
  680. X#define nextnode(X) ((X)->next)
  681. X#define prevnode(X) ((X)->last)
  682. X#define peekfirst(X) ((X)->first->dat)
  683. X#define pushnode(X,Y) insnode(X,(Lknode) X,Y)
  684. X#define incnode(X) (X = nextnode(X))
  685. X#define gethistent(X) (histentarr+((X)%histentct))
  686. X
  687. X/* node structure for syntax trees */
  688. X
  689. X/* struct list, struct sublist, struct pline, etc.  all fit the form
  690. X    of this structure and are used interchangably
  691. X*/
  692. X
  693. Xstruct node {
  694. X    int data[4];            /* arbitrary integer data */
  695. X    vptr ptrs[4];            /* arbitrary pointer data */
  696. X    int types[4];            /* what ptrs[] are pointing to */
  697. X    int type;                /* node type */
  698. X    };
  699. X
  700. X#define N_LIST 0
  701. X#define N_SUBLIST 1
  702. X#define N_PLINE 2
  703. X#define N_CMD 3
  704. X#define N_REDIR 4
  705. X#define N_COND 5
  706. X#define N_FOR 6
  707. X#define N_CASE 7
  708. X#define N_IF 8
  709. X#define N_WHILE 9
  710. X#define N_VARASG 10
  711. X#define N_COUNT 11
  712. X
  713. X/* values for types[4] */
  714. X
  715. X#define NT_EMPTY 0
  716. X#define NT_NODE  1
  717. X#define NT_STR   2
  718. X#define NT_LIST  4
  719. X#define NT_MALLOC 8
  720. X
  721. X/* tree element for lists */
  722. X
  723. Xstruct list {
  724. X    int type;
  725. X    int ifil[3];        /* to fit struct node */
  726. X   Sublist left;
  727. X   List right;
  728. X   };
  729. X
  730. X#define SYNC 0        /* ; */
  731. X#define ASYNC 1    /* & */
  732. X#define TIMED 2
  733. X
  734. X/* tree element for sublists */
  735. X
  736. Xstruct sublist {
  737. X    int type;
  738. X    int flags;            /* see PFLAGs below */
  739. X    int ifil[2];
  740. X    Pline left;
  741. X    Sublist right;
  742. X    };
  743. X
  744. X#define ORNEXT 10        /* || */
  745. X#define ANDNEXT 11    /* && */
  746. X
  747. X#define PFLAG_NOT 1            /* ! ... */
  748. X#define PFLAG_COPROC 32        /* coproc ... */
  749. X
  750. X/* tree element for pipes */
  751. X
  752. Xstruct pline {
  753. X    int type;
  754. X    int ifil[3];
  755. X   Cmd left;
  756. X   Pline right;
  757. X   };
  758. X
  759. X#define END        0    /* pnode *right is null */
  760. X#define PIPE    1    /* pnode *right is the rest of the pipeline */
  761. X
  762. X/* tree element for commands */
  763. X
  764. Xstruct cmd {
  765. X    int type;
  766. X    int flags;                /* see CFLAGs below */
  767. X    int ifil[2];
  768. X   Lklist args;            /* command & argmument List (char *'s) */
  769. X    union {
  770. X       List list;            /* for SUBSH/CURSH/SHFUNC */
  771. X        struct forcmd *forcmd;
  772. X        struct casecmd *casecmd;
  773. X        struct ifcmd *ifcmd;
  774. X        struct whilecmd *whilecmd;
  775. X        Sublist pline;
  776. X        Cond cond;
  777. X        } u;
  778. X   Lklist redir;            /* i/o redirections (struct redir *'s) */
  779. X    Lklist vars;            /* param assignments (struct varasg *'s) */
  780. X   };
  781. X
  782. X#define SIMPLE 0
  783. X#define SUBSH 1
  784. X#define CURSH 2
  785. X#define ZCTIME 3
  786. X#define FUNCDEF 4
  787. X#define CFOR 5
  788. X#define CWHILE 6
  789. X#define CREPEAT 7
  790. X#define CIF 8
  791. X#define CCASE 9
  792. X#define CSELECT 10
  793. X#define COND 11
  794. X
  795. X#define CFLAG_EXEC 1            /* exec ... */
  796. X#define CFLAG_COMMAND 2        /* command ... */
  797. X#define CFLAG_NOGLOB 4     /* noglob ... */
  798. X#define CFLAG_DASH 8            /* - ... */
  799. X
  800. X/* tree element for redirection lists */
  801. X
  802. Xstruct redir {
  803. X    int type,fd1,fd2,ifil;
  804. X    char *name;
  805. X   };
  806. X
  807. X/* tree element for conditionals */
  808. X
  809. Xstruct cond {
  810. X    int type;        /* can be cond_type, or a single letter (-a, -b, ...) */
  811. X    int ifil[3];
  812. X    vptr left,right,vfil[2];
  813. X    int types[4],typ;    /* from struct node.  DO NOT REMOVE */
  814. X    };
  815. X
  816. X#define COND_NOT 0
  817. X#define COND_AND 1
  818. X#define COND_OR 2
  819. X#define COND_STREQ 3
  820. X#define COND_STRNEQ 4
  821. X#define COND_STRLT 5
  822. X#define COND_STRGTR 6
  823. X#define COND_NT 7
  824. X#define COND_OT 8
  825. X#define COND_EF 9
  826. X#define COND_EQ 10
  827. X#define COND_NE 11
  828. X#define COND_LT 12
  829. X#define COND_GT 13
  830. X#define COND_LE 14
  831. X#define COND_GE 15
  832. X
  833. Xstruct forcmd {        /* for/select */
  834. X                            /* Cmd->args contains list of words to loop thru */
  835. X    int inflag;            /* if there is an in ... clause */
  836. X    int ifil[3];
  837. X    char *name;            /* parameter to assign values to */
  838. X    List list;            /* list to look through for each name */
  839. X    };
  840. Xstruct casecmd {
  841. X                            /* Cmd->args contains word to test */
  842. X    int ifil[4];
  843. X    struct casecmd *next;
  844. X    char *pat;
  845. X    List list;                    /* list to execute */
  846. X    };
  847. X
  848. X/*
  849. X
  850. X    a command like "if foo then bar elif baz then fubar else fooble"
  851. X    generates a tree like:
  852. X
  853. X    struct ifcmd a = { next =  &b,  ifl = "foo", thenl = "bar" }
  854. X    struct ifcmd b = { next =  &c,  ifl = "baz", thenl = "fubar" }
  855. X    struct ifcmd c = { next = NULL, ifl = NULL, thenl = "fooble" }
  856. X
  857. X*/
  858. X
  859. Xstruct ifcmd {
  860. X    int ifil[4];
  861. X    struct ifcmd *next;
  862. X    List ifl;
  863. X    List thenl;
  864. X    };
  865. X
  866. Xstruct whilecmd {
  867. X    int cond;        /* 0 for while, 1 for until */
  868. X    int ifil[3];
  869. X    List cont;        /* condition */
  870. X    List loop;        /* list to execute until condition met */
  871. X    };
  872. X
  873. X/* structure used for multiple i/o redirection */
  874. X/* one for each fd open */
  875. X
  876. Xstruct multio {
  877. X    int ct;                /* # of redirections on this fd */
  878. X    int rflag;            /* 0 if open for reading, 1 if open for writing */
  879. X    int pipe;            /* fd of pipe if ct > 1 */
  880. X    int fds[NOFILE];    /* list of src/dests redirected to/from this fd */
  881. X   }; 
  882. X
  883. X/* node used in command path hash table (cmdnamtab) */
  884. X
  885. Xstruct cmdnam 
  886. X{
  887. X    struct hashnode *next; int canfree; char *nam; /* hash data */
  888. X    int type,flags;
  889. X    union {
  890. X        char *nam;        /* full pathname if type != BUILTIN */
  891. X        int binnum;        /* func to exec if type == BUILTIN */
  892. X        List list;        /* list to exec if type == SHFUNC */
  893. X        } u;
  894. X    char **pcomp;        /* location in path for EXCMD's */
  895. X    };
  896. X
  897. X#define EXCMD 0
  898. X#define BUILTIN 2
  899. X#define SHFUNC 3
  900. X#define DISABLED 4
  901. X#define ISEXCMD(X) ((X)==EXCMD)
  902. X
  903. X/* node used in parameter hash table (paramtab) */
  904. X
  905. Xstruct param {
  906. X    struct hashnode *next; int canfree; char *nam; /* hash data */
  907. X    union {
  908. X        char **arr;        /* value if declared array */
  909. X        char *str;        /* value if declared string (scalar) */
  910. X        long val;        /* value if declared integer */
  911. X        } u;
  912. X    union {                /* functions to call to set value */
  913. X        void (*cfn)DCLPROTO((Param,char *));
  914. X        void (*ifn)DCLPROTO((Param,long));
  915. X        void (*afn)DCLPROTO((Param,char **));
  916. X        } sets;
  917. X    union {                /* functions to call to get value */
  918. X        char *(*cfn)DCLPROTO((Param));
  919. X        long (*ifn)DCLPROTO((Param));
  920. X        char **(*afn)DCLPROTO((Param));
  921. X        } gets;
  922. X    int ct;                /* output base or field width */
  923. X    int flags;
  924. X    vptr data;            /* used by getfns */
  925. X    char *env;            /* location in environment, if exported */
  926. X    char *ename;        /* name of corresponding environment var */
  927. X    };
  928. X
  929. X#define PMFLAG_s 0        /* scalar */
  930. X#define PMFLAG_L 1        /* left justify and remove leading blanks */
  931. X#define PMFLAG_R 2        /* right justify and fill with leading blanks */
  932. X#define PMFLAG_Z 4        /* right justify and fill with leading zeros */
  933. X#define PMFLAG_i 8        /* integer */
  934. X#define PMFLAG_l 16        /* all lower case */
  935. X#define PMFLAG_u 32        /* all upper case */
  936. X#define PMFLAG_r 64        /* readonly */
  937. X#define PMFLAG_t 128        /* tagged */
  938. X#define PMFLAG_x 256        /* exported */
  939. X#define PMFLAG_A 512        /* array */
  940. X#define PMFLAG_SPECIAL    1024
  941. X#define PMTYPE (PMFLAG_i|PMFLAG_A)
  942. X#define pmtype(X) ((X)->flags & PMTYPE)
  943. X
  944. X/* variable assignment tree element */
  945. X
  946. Xstruct varasg {
  947. X    int type;            /* nonzero means array */
  948. X    int ifil[3];
  949. X    char *name;
  950. X    char *str;            /* should've been a union here.  oh well */
  951. X    Lklist arr;
  952. X    };
  953. X
  954. X/* lvalue for variable assignment/expansion */
  955. X
  956. Xstruct value {
  957. X    int isarr;
  958. X    struct param *pm;        /* parameter node */
  959. X    int a;                    /* first element of array slice, or -1 */
  960. X    int b;                    /* last element of array slice, or -1 */
  961. X    };
  962. X
  963. Xstruct fdpair {
  964. X    int fd1,fd2;
  965. X    };
  966. X
  967. X/* tty state structure */
  968. X
  969. Xstruct ttyinfo {
  970. X#ifdef TERMIOS
  971. X    struct termios tio;
  972. X#else
  973. X#ifdef TERMIO
  974. X    struct termio tio;
  975. X#else
  976. X    struct sgttyb sgttyb;
  977. X    int lmodes;
  978. X    struct tchars tchars;
  979. X    struct ltchars ltchars;
  980. X#endif
  981. X#endif
  982. X#ifdef TIOCGWINSZ
  983. X    struct winsize winsize;
  984. X#endif
  985. X    };
  986. X
  987. XEXTERN struct ttyinfo savedttyinfo;
  988. X
  989. X/* entry in job table */
  990. X
  991. Xstruct job {
  992. X    long gleader;                    /* process group leader of this job */
  993. X    int stat;
  994. X    char *pwd;                        /* current working dir of shell when
  995. X                                            this job was spawned */
  996. X    struct process *procs;        /* list of processes */
  997. X    Lklist filelist;                /* list of files to delete when done */
  998. X    };
  999. X
  1000. X#define STAT_CHANGED 1        /* status changed and not reported */
  1001. X#define STAT_STOPPED 2        /* all procs stopped or exited */
  1002. X#define STAT_TIMED 4            /* job is being timed */
  1003. X#define STAT_DONE 8
  1004. X#define STAT_LOCKED 16        /* shell is finished creating this job,
  1005. X                                        may be deleted from job table */
  1006. X#define STAT_INUSE 64        /* this job entry is in use */
  1007. X
  1008. X#define SP_RUNNING -1        /* fake statusp for running jobs */
  1009. X
  1010. X#ifndef RUSAGE_CHILDREN
  1011. X#undef HAS_RUSAGE
  1012. X#endif
  1013. X
  1014. Xstruct timeinfo {
  1015. X#ifdef HAS_RUSAGE
  1016. X    struct rusage ru;
  1017. X#else
  1018. X    long ut, st;
  1019. X#endif
  1020. X};
  1021. X
  1022. X/* node in job process lists */
  1023. X
  1024. X#define JOBTEXTSIZE 80
  1025. X
  1026. Xstruct process {
  1027. X    struct process *next;
  1028. X    long pid;
  1029. X    char text[JOBTEXTSIZE];        /* text to print when 'jobs' is run */
  1030. X    int statusp;                    /* return code from wait3() */
  1031. X    struct timeinfo ti;
  1032. X    time_t bgtime;                    /* time job was spawned */
  1033. X    time_t endtime;                /* time job exited */
  1034. X    };
  1035. X
  1036. X/* node in alias hash table */
  1037. X
  1038. Xstruct alias {
  1039. X    struct hashnode *next; int canfree; char *nam; /* hash data */
  1040. X    char *text;            /* expansion of alias */
  1041. X    int cmd;                /* one for regular aliases,
  1042. X                                zero for global aliases,
  1043. X                                negative for reserved words */
  1044. X    int inuse;            /* alias is being expanded */
  1045. X    };
  1046. X
  1047. X/* node in sched list */
  1048. X
  1049. Xstruct schedcmd {
  1050. X    struct schedcmd *next;
  1051. X    char *cmd;        /* command to run */
  1052. X    time_t time;    /* when to run it */
  1053. X    };
  1054. X
  1055. X#define MAXAL 20    /* maximum number of aliases expanded at once */
  1056. X
  1057. X/* hash table node */
  1058. X
  1059. Xstruct hashnode {
  1060. X    struct hashnode *next;
  1061. X    int canfree;        /* nam is free()able */
  1062. X    char *nam;
  1063. X    };
  1064. X
  1065. X/* hash table */
  1066. X
  1067. Xstruct hashtab {
  1068. X    int hsize;                            /* size of nodes[] */
  1069. X    int ct;                                /* # of elements */
  1070. X    struct hashnode **nodes;        /* array of size hsize */
  1071. X    };
  1072. X
  1073. X/* history entry */
  1074. X
  1075. Xstruct histent {
  1076. X    char *lex;            /* lexical history line */
  1077. X    char *lit;            /* literal history line */
  1078. X    time_t stim;        /* command started time (datestamp) */
  1079. X    time_t ftim;        /* command finished time */
  1080. X    };
  1081. X
  1082. X/* completion control */
  1083. X
  1084. Xstruct compctl {
  1085. X    struct hashnode *next; int canfree; char *nam; /* hash data */
  1086. X    int mask;
  1087. X    char *keyvar;
  1088. X    };
  1089. X
  1090. X#define CC_FILES        1
  1091. X#define CC_COMMPATH    2
  1092. X#define CC_HOSTS        4
  1093. X#define CC_OPTIONS    8
  1094. X#define CC_VARS        16
  1095. X#define CC_BINDINGS    32
  1096. X#define CC_USRKEYS   64
  1097. X
  1098. Xextern char *sys_errlist[];
  1099. Xextern int errno;
  1100. X
  1101. X/* values in opts[] array */
  1102. X
  1103. X#define OPT_INVALID 1    /* opt is invalid, like -$ */
  1104. X#define OPT_UNSET 0
  1105. X#define OPT_SET 2
  1106. X
  1107. X/* the options */
  1108. X
  1109. Xstruct option {
  1110. X    char *name;
  1111. X    char id;            /* corresponding letter */
  1112. X    };
  1113. X
  1114. X#define CORRECT '0'
  1115. X#define NOCLOBBER '1'
  1116. X#define NOBADPATTERN '2'
  1117. X#define NONOMATCH '3'
  1118. X#define GLOBDOTS '4'
  1119. X#define NOTIFY '5'
  1120. X#define BGNICE '6'
  1121. X#define IGNOREEOF '7'
  1122. X#define MARKDIRS '8'
  1123. X#define AUTOLIST '9'
  1124. X#define NOBEEP 'B'
  1125. X#define PRINTEXITVALUE 'C'
  1126. X#define PUSHDTOHOME 'D'
  1127. X#define PUSHDSILENT 'E'
  1128. X#define NOGLOBOPT 'F'
  1129. X#define NULLGLOB 'G'
  1130. X#define RMSTARSILENT 'H'
  1131. X#define IGNOREBRACES 'I'
  1132. X#define AUTOCD 'J'
  1133. X#define NOBANGHIST 'K'
  1134. X#define SUNKEYBOARDHACK 'L'
  1135. X#define SINGLELINEZLE 'M'
  1136. X#define AUTOPUSHD 'N'
  1137. X#define CORRECTALL 'O'
  1138. X#define RCEXPANDPARAM 'P'
  1139. X#define PATHDIRS 'Q'
  1140. X#define LONGLISTJOBS 'R'
  1141. X#define RECEXACT 'S'
  1142. X#define CDABLEVARS 'T'
  1143. X#define MAILWARNING 'U'
  1144. X#define NOPROMPTCR 'V'
  1145. X#define AUTORESUME 'W'
  1146. X#define LISTTYPES 'X'
  1147. X#define MENUCOMPLETE 'Y'
  1148. X#define USEZLE 'Z'
  1149. X#define ALLEXPORT 'a'
  1150. X#define ERREXIT 'e'
  1151. X#define NORCS 'f'
  1152. X#define HISTIGNORESPACE 'g'
  1153. X#define HISTIGNOREDUPS 'h'
  1154. X#define INTERACTIVE 'i'
  1155. X#define HISTLIT 'j'
  1156. X#define INTERACTIVECOMMENTS 'k'
  1157. X#define LOGINSHELL 'l'
  1158. X#define MONITOR 'm'
  1159. X#define NOEXEC 'n'
  1160. X#define SHINSTDIN 's'
  1161. X#define NOUNSET 'u'
  1162. X#define VERBOSE 'v'
  1163. X#define CHASELINKS 'w'
  1164. X#define XTRACE 'x'
  1165. X#define SHWORDSPLIT 'y'
  1166. X#define MENUCOMPLETEBEEP '\2'
  1167. X#define HISTNOSTORE '\3'
  1168. X#define EXTENDEDGLOB '\5'
  1169. X#define GLOBCOMPLETE '\6'
  1170. X#define CSHJUNKIEQUOTES '\7'
  1171. X#define PUSHDMINUS '\10'
  1172. X#define CSHJUNKIELOOPS '\11'
  1173. X#define RCQUOTES '\12'
  1174. X#define KSHOPTIONPRINT '\13'
  1175. X#define NOSHORTLOOPS '\14'
  1176. X#define LASTMENU '\15'
  1177. X#define AUTOMENU '\16'
  1178. X#define HISTVERIFY '\17'
  1179. X#define NOLISTBEEP '\20'
  1180. X#define NOHUP '\21'
  1181. X#define NOEQUALS '\22'
  1182. X#define CSHNULLGLOB '\23'
  1183. X#define HASHCMDS '\24'
  1184. X#define HASHDIRS '\25'
  1185. X#define NUMERICGLOBSORT '\26'
  1186. X#define BRACECCL '\27'
  1187. X#define HASHLISTALL '\30'
  1188. X#define OVERSTRIKE '\31'
  1189. X#define NOHISTBEEP '\32'
  1190. X#define PUSHDIGNOREDUPS '\33'
  1191. X#define AUTOREMOVESLASH '\34'
  1192. X
  1193. X#ifndef GLOBALS
  1194. Xextern struct option optns[];
  1195. X#else
  1196. Xstruct option optns[] = {
  1197. X    "correct",CORRECT,
  1198. X    "noclobber",NOCLOBBER,
  1199. X    "nobadpattern",NOBADPATTERN,
  1200. X    "nonomatch",NONOMATCH,
  1201. X    "globdots",GLOBDOTS,
  1202. X    "notify",NOTIFY,
  1203. X    "bgnice",BGNICE,
  1204. X    "ignoreeof",IGNOREEOF,
  1205. X    "markdirs",MARKDIRS,
  1206. X    "autolist",AUTOLIST,
  1207. X    "nobeep",NOBEEP,
  1208. X    "printexitvalue",PRINTEXITVALUE,
  1209. X    "pushdtohome",PUSHDTOHOME,
  1210. X    "pushdsilent",PUSHDSILENT,
  1211. X    "noglob",NOGLOBOPT,
  1212. X    "nullglob",NULLGLOB,
  1213. X    "rmstarsilent",RMSTARSILENT,
  1214. X    "ignorebraces",IGNOREBRACES,
  1215. X    "braceccl",BRACECCL,
  1216. X    "autocd",AUTOCD,
  1217. X    "nobanghist",NOBANGHIST,
  1218. X    "sunkeyboardhack",SUNKEYBOARDHACK,
  1219. X    "singlelinezle",SINGLELINEZLE,
  1220. X    "autopushd",AUTOPUSHD,
  1221. X    "correctall",CORRECTALL,
  1222. X    "rcexpandparam",RCEXPANDPARAM,
  1223. X    "pathdirs",PATHDIRS,
  1224. X    "longlistjobs",LONGLISTJOBS,
  1225. X    "recexact",RECEXACT,
  1226. X    "cdablevars",CDABLEVARS,
  1227. X    "mailwarning",MAILWARNING,
  1228. X    "nopromptcr",NOPROMPTCR,
  1229. X    "autoresume",AUTORESUME,
  1230. X    "listtypes",LISTTYPES,
  1231. X    "menucomplete",MENUCOMPLETE,
  1232. X    "zle",USEZLE,
  1233. X    "allexport",ALLEXPORT,
  1234. X    "errexit",ERREXIT,
  1235. X    "norcs",NORCS,
  1236. X    "histignorespace",HISTIGNORESPACE,
  1237. X    "histignoredups",HISTIGNOREDUPS,
  1238. X    "interactive",INTERACTIVE,
  1239. X    "histlit",HISTLIT,
  1240. X    "interactivecomments",INTERACTIVECOMMENTS,
  1241. X    "login",LOGINSHELL,
  1242. X    "monitor",MONITOR,
  1243. X    "noexec",NOEXEC,
  1244. X    "shinstdin",SHINSTDIN,
  1245. X    "nounset",NOUNSET,
  1246. X    "verbose",VERBOSE,
  1247. X    "chaselinks",CHASELINKS,
  1248. X    "xtrace",XTRACE,
  1249. X    "shwordsplit",SHWORDSPLIT,
  1250. X    "menucompletebeep",MENUCOMPLETEBEEP,
  1251. X    "histnostore",HISTNOSTORE,
  1252. X    "extendedglob",EXTENDEDGLOB,
  1253. X    "globcomplete",GLOBCOMPLETE,
  1254. X    "cshjunkiequotes",CSHJUNKIEQUOTES,
  1255. X    "pushdminus",PUSHDMINUS,
  1256. X    "cshjunkieloops",CSHJUNKIELOOPS,
  1257. X    "rcquotes",RCQUOTES,
  1258. X    "noshortloops",NOSHORTLOOPS,
  1259. X    "lastmenu",LASTMENU,
  1260. X    "automenu",AUTOMENU,
  1261. X    "histverify",HISTVERIFY,
  1262. X    "nolistbeep",NOLISTBEEP,
  1263. X    "nohup",NOHUP,
  1264. X    "noequals",NOEQUALS,
  1265. X    "kshoptionprint",KSHOPTIONPRINT,
  1266. X    "cshnullglob",CSHNULLGLOB,
  1267. X    "hashcmds",HASHCMDS,
  1268. X    "hashdirs",HASHDIRS,
  1269. X    "numericglobsort",NUMERICGLOBSORT,
  1270. X    "hashlistall",HASHLISTALL,
  1271. X    "overstrike",OVERSTRIKE,
  1272. X    "nohistbeep",NOHISTBEEP,
  1273. X    "pushdignoredups",PUSHDIGNOREDUPS,
  1274. X    "autoremoveslash",AUTOREMOVESLASH,
  1275. X    NULL,0
  1276. X};
  1277. X#endif
  1278. X
  1279. X#define ALSTAT_MORE 1    /* last alias ended with ' ' */
  1280. X#define ALSTAT_JUNK 2    /* don't put word in history List */
  1281. X
  1282. X#undef isset
  1283. X#define isset(X) (opts[X])
  1284. X#define unset(X) (!opts[X])
  1285. X#define interact (isset(INTERACTIVE))
  1286. X#define jobbing (isset(MONITOR))
  1287. X#define nointr() signal(SIGINT,SIG_IGN)
  1288. X#define islogin (isset(LOGINSHELL))
  1289. X
  1290. X#ifndef _IBMR2
  1291. X#undef WIFSTOPPED
  1292. X#undef WIFSIGNALED
  1293. X#undef WIFEXITED
  1294. X#undef WEXITSTATUS
  1295. X#undef WTERMSIG
  1296. X#undef WSTOPSIG
  1297. X#undef WCOREDUMPED
  1298. X
  1299. X#define WIFSTOPPED(X) (((X)&0377)==0177)
  1300. X#define WIFSIGNALED(X) (((X)&0377)!=0&&((X)&0377)!=0177)
  1301. X#define WIFEXITED(X) (((X)&0377)==0)
  1302. X#define WEXITSTATUS(X) (((X)>>8)&0377)
  1303. X#define WTERMSIG(X) ((X)&0177)
  1304. X#define WSTOPSIG(X) (((X)>>8)&0377)
  1305. X#endif
  1306. X#define WCOREDUMPED(X) ((X)&0200)
  1307. X
  1308. X#ifndef S_ISBLK
  1309. X#define    _IFMT        0170000
  1310. X#define    _IFDIR    0040000
  1311. X#define    _IFCHR    0020000
  1312. X#define    _IFBLK    0060000
  1313. X#define    _IFREG    0100000
  1314. X#define    _IFIFO    0010000
  1315. X#define    S_ISBLK(m)    (((m)&_IFMT) == _IFBLK)
  1316. X#define    S_ISCHR(m)    (((m)&_IFMT) == _IFCHR)
  1317. X#define    S_ISDIR(m)    (((m)&_IFMT) == _IFDIR)
  1318. X#define    S_ISFIFO(m)    (((m)&_IFMT) == _IFIFO)
  1319. X#define    S_ISREG(m)    (((m)&_IFMT) == _IFREG)
  1320. X#endif
  1321. X
  1322. X#ifndef S_ISSOCK
  1323. X#ifndef _IFMT
  1324. X#define _IFMT 0170000
  1325. X#endif
  1326. X#define    _IFLNK    0120000
  1327. X#define    _IFSOCK    0140000
  1328. X#define    S_ISLNK(m)    (((m)&_IFMT) == _IFLNK)
  1329. X#define    S_ISSOCK(m)    (((m)&_IFMT) == _IFSOCK)
  1330. X#endif
  1331. X
  1332. X#if S_IFIFO == S_IFSOCK
  1333. X#undef S_IFIFO
  1334. X#endif
  1335. X
  1336. X#ifndef S_IFIFO
  1337. X#define NO_FIFOS
  1338. X#endif
  1339. X
  1340. X/* buffered shell input for non-interactive shells */
  1341. X
  1342. XEXTERN FILE *bshin;
  1343. X
  1344. X/* NULL-terminated arrays containing path, cdpath, etc. */
  1345. X
  1346. XEXTERN char **path,**cdpath,**fpath,**watch,**mailpath;
  1347. XEXTERN char **manpath,**tildedirs,**fignore;
  1348. XEXTERN char **hosts;
  1349. X
  1350. X/* named directories */
  1351. X
  1352. XEXTERN char **userdirs,**usernames;
  1353. X
  1354. X/* size of userdirs[], # of userdirs */
  1355. X
  1356. XEXTERN int userdirsz,userdirct;
  1357. X
  1358. XEXTERN char *mailfile;
  1359. X
  1360. XEXTERN char *yytext;
  1361. X
  1362. X/* error/break flag */
  1363. X
  1364. XEXTERN int errflag;
  1365. X
  1366. XEXTERN char *tokstr;
  1367. XEXTERN int tok, tokfd;
  1368. X
  1369. X/* lexical analyzer error flag */
  1370. X
  1371. XEXTERN int lexstop;
  1372. X
  1373. X/* suppress error messages */
  1374. X
  1375. XEXTERN int noerrs;
  1376. X
  1377. X/* current history event number */
  1378. X
  1379. XEXTERN int curhist;
  1380. X
  1381. X/* if != 0, this is the first line of the command */
  1382. X
  1383. XEXTERN int isfirstln;
  1384. X
  1385. X/* if != 0, this is the first char of the command (not including
  1386. X    white space */
  1387. X
  1388. XEXTERN int isfirstch;
  1389. X
  1390. X/* number of history entries */
  1391. X
  1392. XEXTERN int histentct;
  1393. X
  1394. X/* array of history entries */
  1395. X
  1396. XEXTERN Histent histentarr;
  1397. X
  1398. X/* capacity of history lists */
  1399. X
  1400. XEXTERN int histsiz,lithistsiz;
  1401. X
  1402. X/* if = 1, we have performed history substitution on the current line
  1403. X     if = 2, we have used the 'p' modifier */
  1404. X
  1405. XEXTERN int histdone;
  1406. X
  1407. X/* default event (usually curhist-1, that is, "!!") */
  1408. X
  1409. XEXTERN int defev;
  1410. X
  1411. X/* != 0 if we are about to read a command word */
  1412. X
  1413. XEXTERN int incmdpos;
  1414. X
  1415. X/* != 0 if we are in the middle of a [[ ... ]] */
  1416. X
  1417. XEXTERN int incond;
  1418. X
  1419. X/* != 0 if we are after a redirection (for ctxtlex only) */
  1420. X
  1421. XEXTERN int inredir;
  1422. X
  1423. X/* != 0 if we are about to read a case pattern */
  1424. X
  1425. XEXTERN int incasepat;
  1426. X
  1427. X/* != 0 if we just read FUNCTION */
  1428. X
  1429. XEXTERN int infunc;
  1430. X
  1431. X/* != 0 if we just read a newline */
  1432. X
  1433. XEXTERN int isnewlin;
  1434. X
  1435. X/* the lists of history events */
  1436. X
  1437. XEXTERN Lklist histlist,lithistlist;
  1438. X
  1439. X/* the directory stack */
  1440. X
  1441. XEXTERN Lklist dirstack;
  1442. X
  1443. X/* the zle buffer stack */
  1444. X
  1445. XEXTERN Lklist bufstack;
  1446. X
  1447. X/* the input queue (stack?)
  1448. X
  1449. X    inbuf    = start of buffer
  1450. X    inbufptr = location in buffer (= inbuf for a FULL buffer)
  1451. X                                            (= inbuf+inbufsz for an EMPTY buffer)
  1452. X    inbufct  = # of chars in buffer (inbufptr+inbufct == inbuf+inbufsz)
  1453. X    inbufsz  = max size of buffer
  1454. X*/
  1455. X
  1456. XEXTERN char *inbuf,*inbufptr;
  1457. XEXTERN int inbufct,inbufsz;
  1458. X
  1459. XEXTERN char *ifs;        /* $IFS */
  1460. X
  1461. XEXTERN char *oldpwd;    /* $OLDPWD */
  1462. X
  1463. XEXTERN char *underscore; /* $_ */
  1464. X
  1465. X/* != 0 if this is a subshell */
  1466. X
  1467. XEXTERN int subsh;
  1468. X
  1469. X/* # of break levels */
  1470. X
  1471. XEXTERN int breaks;
  1472. X
  1473. X/* != 0 if we have a return pending */
  1474. X
  1475. XEXTERN int retflag;
  1476. X
  1477. X/* how far we've hashed the PATH so far */
  1478. X
  1479. XEXTERN char **pathchecked;
  1480. X
  1481. X/* # of nested loops we are in */
  1482. X
  1483. XEXTERN int loops;
  1484. X
  1485. X/* # of continue levels */
  1486. X
  1487. XEXTERN int contflag;
  1488. X
  1489. X/* the job we are working on */
  1490. X
  1491. XEXTERN int thisjob;
  1492. X
  1493. X/* the current job (+) */
  1494. X
  1495. XEXTERN int curjob;
  1496. X
  1497. X/* the previous job (-) */
  1498. X
  1499. XEXTERN int prevjob;
  1500. X
  1501. X/* hash table containing the aliases and reserved words */
  1502. X
  1503. XEXTERN Hashtab aliastab;
  1504. X
  1505. X/* hash table containing the parameters */
  1506. X
  1507. XEXTERN Hashtab paramtab;
  1508. X
  1509. X/* hash table containing the builtins/shfuncs/hashed commands */
  1510. X
  1511. XEXTERN Hashtab cmdnamtab;
  1512. X
  1513. X/* hash table containing the zle multi-character bindings */
  1514. X
  1515. XEXTERN Hashtab xbindtab;
  1516. X
  1517. X/* hash table for completion info for commands */
  1518. X
  1519. XEXTERN Hashtab compctltab;
  1520. X
  1521. X/* default completion infos */
  1522. X
  1523. XEXTERN struct compctl cc_compos, cc_default;
  1524. X
  1525. X/* the job table */
  1526. X
  1527. XEXTERN struct job jobtab[MAXJOB];
  1528. X
  1529. X/* shell timings */
  1530. X
  1531. X#ifndef HAS_RUSAGE
  1532. XEXTERN struct tms shtms;
  1533. X#endif
  1534. X
  1535. X/* the list of sched jobs pending */
  1536. X
  1537. XEXTERN struct schedcmd *schedcmds;
  1538. X
  1539. X/* the last l for s/l/r/ history substitution */
  1540. X
  1541. XEXTERN char *hsubl;
  1542. X
  1543. X/* the last r for s/l/r/ history substitution */
  1544. X
  1545. XEXTERN char *hsubr;
  1546. X
  1547. XEXTERN char *username;    /* $USERNAME */
  1548. XEXTERN char *logname;    /* $LOGNAME */
  1549. XEXTERN long lastval;        /* $? */
  1550. XEXTERN long baud;            /* $BAUD */
  1551. XEXTERN long columns;        /* $COLUMNS */
  1552. XEXTERN long lines;        /* $LINES */
  1553. XEXTERN long reporttime; /* $REPORTTIME */
  1554. X
  1555. X/* input fd from the coprocess */
  1556. X
  1557. XEXTERN int coprocin;
  1558. X
  1559. X/* output fd from the coprocess */
  1560. X
  1561. XEXTERN int coprocout;
  1562. X
  1563. XEXTERN long mailcheck;    /* $MAILCHECK */
  1564. XEXTERN long logcheck;    /* $LOGCHECK */
  1565. X
  1566. X/* the last time we checked mail */
  1567. X
  1568. XEXTERN time_t lastmailcheck;
  1569. X
  1570. X/* the last time we checked the people in the WATCH variable */
  1571. X
  1572. XEXTERN time_t lastwatch;
  1573. X
  1574. X/* the last time we did the periodic() shell function */
  1575. X
  1576. XEXTERN time_t lastperiod;
  1577. X
  1578. X/* $SECONDS = time(NULL) - shtimer */
  1579. X
  1580. XEXTERN time_t shtimer;
  1581. X
  1582. XEXTERN long mypid;        /* $$ */
  1583. XEXTERN long lastpid;        /* $! */
  1584. XEXTERN long ppid;            /* $PPID */
  1585. X
  1586. X/* the process group of the shell */
  1587. X
  1588. XEXTERN long mypgrp;
  1589. X
  1590. XEXTERN char *pwd;            /* $PWD */
  1591. XEXTERN char *optarg;        /* $OPTARG */
  1592. XEXTERN long zoptind;        /* $OPTIND */
  1593. XEXTERN char *prompt;        /* $PROMPT */
  1594. XEXTERN char *rprompt;    /* $RPROMPT */
  1595. XEXTERN char *prompt2;    /* etc. */
  1596. XEXTERN char *prompt3;
  1597. XEXTERN char *prompt4;
  1598. XEXTERN char *sprompt;
  1599. XEXTERN char *timefmt;
  1600. XEXTERN char *watchfmt;
  1601. XEXTERN char *wordchars;
  1602. XEXTERN char *fceditparam;
  1603. XEXTERN char *tmpprefix;
  1604. XEXTERN char *rstring, *Rstring;
  1605. XEXTERN char *postedit;
  1606. X
  1607. XEXTERN char *argzero;    /* $0 */
  1608. X
  1609. XEXTERN char *hackzero;
  1610. X
  1611. X/* the hostname */
  1612. X
  1613. XEXTERN char *hostnam;
  1614. X
  1615. XEXTERN char *home;        /* $HOME */
  1616. XEXTERN char **pparams;    /* $argv */
  1617. X
  1618. X/* the default command for null commands */
  1619. X
  1620. XEXTERN char *nullcmd;
  1621. XEXTERN char *readnullcmd;
  1622. X
  1623. X/* the List of local variables we have to destroy */
  1624. X
  1625. XEXTERN Lklist locallist;
  1626. X
  1627. X/* the shell input fd */
  1628. X
  1629. XEXTERN int SHIN;
  1630. X
  1631. X/* the shell tty fd */
  1632. X
  1633. XEXTERN int SHTTY;
  1634. X
  1635. X/* the stack of aliases we are expanding */
  1636. X
  1637. XEXTERN struct alias *alstack[MAXAL];
  1638. X
  1639. X/* the alias stack pointer; also, the number of aliases currently
  1640. X     being expanded */
  1641. X
  1642. XEXTERN int alstackind;
  1643. X
  1644. X/* != 0 means we are reading input from a string */
  1645. X
  1646. XEXTERN int strin;
  1647. X
  1648. X/* period between periodic() commands, in seconds */
  1649. X
  1650. XEXTERN long period;
  1651. X
  1652. X/* != 0 means history substitution is turned off */
  1653. X
  1654. XEXTERN int stophist;
  1655. X
  1656. XEXTERN int lithist;
  1657. X
  1658. X/* this line began with a space, so junk it if HISTIGNORESPACE is on */
  1659. X
  1660. XEXTERN int spaceflag;
  1661. X
  1662. X/* don't do spelling correction */
  1663. X
  1664. XEXTERN int nocorrect;
  1665. X
  1666. X/* != 0 means we have removed the current event from the history List */
  1667. X
  1668. XEXTERN int histremmed;
  1669. X
  1670. X/* the options; e.g. if opts['a'] == OPT_SET, -a is turned on */
  1671. X
  1672. XEXTERN int opts[128];
  1673. X
  1674. XEXTERN long lineno;        /* LINENO */
  1675. XEXTERN long listmax;        /* LISTMAX */
  1676. XEXTERN long savehist;    /* SAVEHIST */
  1677. XEXTERN long shlvl;        /* SHLVL */
  1678. XEXTERN long tmout;        /* TMOUT */
  1679. XEXTERN long dirstacksize;    /* DIRSTACKSIZE */
  1680. X
  1681. X/* != 0 means we have called execlist() and then intend to exit(),
  1682. X     so don't fork if not necessary */
  1683. X
  1684. XEXTERN int exiting;
  1685. X
  1686. XEXTERN int lastbase;        /* last input base we used */
  1687. X
  1688. X/* the limits for child processes */
  1689. X
  1690. X#ifdef RLIM_INFINITY
  1691. XEXTERN struct rlimit limits[RLIM_NLIMITS];
  1692. X#endif
  1693. X
  1694. X/* the current word in the history List */
  1695. X
  1696. XEXTERN char *hlastw;
  1697. X
  1698. X/* pointer into the history line */
  1699. X
  1700. XEXTERN char *hptr;
  1701. X
  1702. X/* the current history line */
  1703. X
  1704. XEXTERN char *hline;
  1705. X
  1706. X/* the termcap buffer */
  1707. X
  1708. XEXTERN char termbuf[1024];
  1709. X
  1710. X/* $TERM */
  1711. X
  1712. XEXTERN char *term;
  1713. X
  1714. X/* != 0 if this $TERM setup is usable */
  1715. X
  1716. XEXTERN int termok;
  1717. X
  1718. X/* flag for CSHNULLGLOB */
  1719. X
  1720. XEXTERN int badcshglob;
  1721. X
  1722. X/* max size of hline */
  1723. X
  1724. XEXTERN int hlinesz;
  1725. X
  1726. X/* the alias expansion status - if == ALSTAT_MORE, we just finished
  1727. X    expanding an alias ending with a space */
  1728. X
  1729. XEXTERN int alstat;
  1730. X
  1731. X/* we have printed a 'you have stopped (running) jobs.' message */
  1732. X
  1733. XEXTERN int stopmsg;
  1734. X
  1735. X/* the default tty state */
  1736. X
  1737. XEXTERN struct ttyinfo shttyinfo;
  1738. X
  1739. X/* $TTY */
  1740. X
  1741. XEXTERN char *ttystrname;
  1742. X
  1743. X/* 1 if ttyctl -f has been executed */
  1744. X
  1745. XEXTERN int ttyfrozen;
  1746. X
  1747. X/* list of memory heaps */
  1748. X
  1749. XEXTERN Lklist heaplist;
  1750. X
  1751. X/* != 0 if we are allocating in the heaplist */
  1752. X
  1753. XEXTERN int useheap;
  1754. X
  1755. X#include "signals.h"
  1756. X
  1757. X#ifdef GLOBALS
  1758. X
  1759. X/* signal names */
  1760. Xchar **sigptr = sigs;
  1761. X
  1762. X/* tokens */
  1763. Xchar *ztokens = "#$^*()$=|{}[]`<>?~`,";
  1764. X
  1765. X#else
  1766. Xextern char *ztokens,**sigptr;
  1767. X#endif
  1768. X
  1769. X#define SIGERR (SIGCOUNT+1)
  1770. X#define SIGDEBUG (SIGCOUNT+2)
  1771. X#define VSIGCOUNT (SIGCOUNT+3)
  1772. X#define SIGEXIT 0
  1773. X
  1774. X/* signals that are trapped = 1, signals ignored =2 */
  1775. X
  1776. XEXTERN int sigtrapped[VSIGCOUNT];
  1777. X
  1778. X/* trap functions for each signal */
  1779. X
  1780. XEXTERN List sigfuncs[VSIGCOUNT];
  1781. X
  1782. X/* $HISTCHARS */
  1783. X
  1784. XEXTERN char bangchar,hatchar,hashchar;
  1785. X
  1786. XEXTERN int eofseen;
  1787. X
  1788. X/* we are parsing a line sent to use by the editor */
  1789. X
  1790. XEXTERN int zleparse;
  1791. X
  1792. XEXTERN int wordbeg;
  1793. X
  1794. XEXTERN int parbegin;
  1795. X
  1796. X/* interesting termcap strings */
  1797. X
  1798. X#define TCCLEARSCREEN 0
  1799. X#define TCLEFT 1
  1800. X#define TCMULTLEFT 2
  1801. X#define TCRIGHT 3
  1802. X#define TCMULTRIGHT 4
  1803. X#define TCUP 5
  1804. X#define TCMULTUP 6
  1805. X#define TCDOWN 7
  1806. X#define TCMULTDOWN 8
  1807. X#define TCDEL 9
  1808. X#define TCMULTDEL 10
  1809. X#define TCINS 11
  1810. X#define TCMULTINS 12
  1811. X#define TCCLEAREOD 13
  1812. X#define TCCLEAREOL 14
  1813. X#define TCINSLINE 15
  1814. X#define TCDELLINE 16
  1815. X#define TC_COUNT 17
  1816. X
  1817. X/* lengths of each string */
  1818. X
  1819. XEXTERN int tclen[TC_COUNT];
  1820. X
  1821. XEXTERN char *tcstr[TC_COUNT];
  1822. X
  1823. X#ifdef GLOBALS
  1824. X
  1825. X/* names of the strings we want */
  1826. X
  1827. Xchar *tccapnams[TC_COUNT] = {
  1828. X    "cl","le","LE","nd","RI","up","UP","do",
  1829. X    "DO","dc","DC","ic","IC","cd","ce","al","dl"
  1830. X    };
  1831. X
  1832. X#else
  1833. Xextern char *tccapnams[TC_COUNT];
  1834. X#endif
  1835. X
  1836. X#define tccan(X) (!!tclen[X])
  1837. X
  1838. X#define HISTFLAG_DONE   1
  1839. X#define HISTFLAG_NOEXEC 2
  1840. X#define HISTFLAG_RECALL 4
  1841. X
  1842. X#include "ztype.h"
  1843. X#include "funcs.h"
  1844. X
  1845. X#ifdef HAS_SETPGID
  1846. X#define setpgrp setpgid
  1847. X#endif
  1848. X
  1849. X#define _INCLUDE_POSIX_SOURCE
  1850. X#define _INCLUDE_XOPEN_SOURCE
  1851. X#define _INCLUDE_HPUX_SOURCE
  1852. X
  1853. X#ifdef SV_BSDSIG
  1854. X#define SV_INTERRUPT SV_BSDSIG
  1855. X#endif
  1856. X
  1857. X#ifdef HAS_SIGRELSE
  1858. X#define blockchld() sighold(SIGCHLD)
  1859. X#define unblockchld() sigrelse(SIGCHLD)
  1860. X#define chldsuspend() sigpause(SIGCHLD)
  1861. X#else
  1862. X#define blockchld() sigblock(sigmask(SIGCHLD))
  1863. X#define unblockchld() sigsetmask(0)
  1864. X#define chldsuspend() sigpause(0)
  1865. X#endif
  1866. SHAR_EOF
  1867. chmod 0644 zsh2.2/src/zsh.h ||
  1868. echo 'restore of zsh2.2/src/zsh.h failed'
  1869. Wc_c="`wc -c < 'zsh2.2/src/zsh.h'`"
  1870. test 31883 -eq "$Wc_c" ||
  1871.     echo 'zsh2.2/src/zsh.h: original size 31883, current size' "$Wc_c"
  1872. rm -f _shar_wnt_.tmp
  1873. fi
  1874. # ============= zsh2.2/src/zle_vi.c ==============
  1875. if test -f 'zsh2.2/src/zle_vi.c' -a X"$1" != X"-c"; then
  1876.     echo 'x - skipping zsh2.2/src/zle_vi.c (File already exists)'
  1877.     rm -f _shar_wnt_.tmp
  1878. else
  1879. > _shar_wnt_.tmp
  1880. echo 'x - extracting zsh2.2/src/zle_vi.c (Text)'
  1881. sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/src/zle_vi.c' &&
  1882. X/*
  1883. X *
  1884. X * zle_vi.c - vi-specific functions
  1885. X *
  1886. X * This file is part of zsh, the Z shell.
  1887. X *
  1888. X * This software is Copyright 1992 by Paul Falstad
  1889. X *
  1890. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  1891. X * use this software as long as: there is no monetary profit gained
  1892. X * specifically from the use or reproduction of this software, it is not
  1893. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  1894. X * included prominently in any copy made. 
  1895. X *
  1896. X * The author make no claims as to the fitness or correctness of this software
  1897. X * for any use whatsoever, and it is provided as is. Any use of this software
  1898. X * is at the user's own risk. 
  1899. X *
  1900. X */
  1901. X
  1902. X#define ZLE
  1903. X#include "zsh.h"
  1904. X
  1905. X
  1906. Xstatic void startvichange(im)
  1907. Xint im;
  1908. X{
  1909. X    insmode = im;
  1910. X    if (vichgbuf) free(vichgbuf);
  1911. X    vichgbuf = zalloc(vichgbufsz = 16);
  1912. X    vichgbuf[0] = c;
  1913. X    vichgbufptr = 1;
  1914. X    vichgflag = 1;
  1915. X    viinsbegin = cs;
  1916. X}
  1917. X
  1918. Xstatic void startvitext(im)
  1919. X{
  1920. X    startvichange(im);
  1921. X    bindtab = mainbindtab;
  1922. X    undoing = 0;
  1923. X}
  1924. X
  1925. Xint vigetkey() /**/
  1926. X{
  1927. Xint ch;
  1928. X
  1929. X    if ((ch = getkey(0)) == -1)
  1930. X        return 0;
  1931. X    if (ch == 22)
  1932. X        {
  1933. X        if ((ch = getkey(0)) == -1)
  1934. X            return 0;
  1935. X        return ch;
  1936. X        }
  1937. X    else if (ch == 27)
  1938. X        return 0;
  1939. X    return ch;
  1940. X}
  1941. X
  1942. Xint getvirange(wf) /**/
  1943. Xint wf;
  1944. X{
  1945. Xint k2,t0,startline,endline;
  1946. X
  1947. X    startline = findbol();
  1948. X    endline = findeol();
  1949. X    for (;;) {
  1950. X        k2 = getkeycmd();
  1951. X        if (k2 == -1) {
  1952. X            feep();
  1953. X            return -1;
  1954. X        }
  1955. X        if (zlecmds[k2].flags & ZLE_ARG)
  1956. X            (*zlecmds[k2].func)();
  1957. X        else
  1958. X            break;
  1959. X    }
  1960. X    if (k2 == bindk) {
  1961. X        findline(&cs,&t0);
  1962. X        return (t0 == ll) ? t0 : t0+1;
  1963. X    }
  1964. X    if (!(zlecmds[k2].flags & ZLE_MOVEMENT)) {
  1965. X        feep();
  1966. X        return -1;
  1967. X    }
  1968. X    t0 = cs;
  1969. X
  1970. X    virangeflag = 1;
  1971. X    wordflag = wf;
  1972. X    (*zlecmds[k2].func)();
  1973. X    wordflag = virangeflag = 0;
  1974. X    if (cs == t0) {
  1975. X        feep();
  1976. X        return -1;
  1977. X    }
  1978. X    if (startline != findbol()) {
  1979. X        if (zlecmds[k2].flags & ZLE_LINEMOVE) {
  1980. X            if (cs < t0) {
  1981. X                cs = startline;
  1982. X                t0 = findeol()+1;
  1983. X            } else {
  1984. X                t0 = startline;
  1985. X                cs = findeol()+1;
  1986. X            }
  1987. X        } else {
  1988. X            if (cs < startline) cs = startline;
  1989. X            else if (cs >= endline) cs = endline-1;
  1990. X        }
  1991. X    }
  1992. X    if (cs > t0) {
  1993. X        k2 = cs;
  1994. X        cs = t0;
  1995. X        t0 = k2;
  1996. X    }
  1997. X    return t0;
  1998. X}
  1999. X
  2000. Xvoid viaddnext() /**/
  2001. X{
  2002. X    if (cs != ll)
  2003. X        cs++;
  2004. X    startvitext(1);
  2005. X}
  2006. X
  2007. Xvoid viaddeol() /**/
  2008. X{
  2009. X    cs = findeol();
  2010. X    startvitext(1);
  2011. X}
  2012. X
  2013. Xvoid viinsert() /**/
  2014. X{
  2015. X    startvitext(1);
  2016. X}
  2017. X
  2018. Xvoid viinsertbol() /**/
  2019. X{
  2020. X    cs = findbol();
  2021. X    startvitext(1);
  2022. X}
  2023. X
  2024. Xvoid videlete() /**/
  2025. X{
  2026. Xint c2;
  2027. X
  2028. X    startvichange(1);
  2029. X    if ((c2 = getvirange(0)) == -1)
  2030. X        { vichgflag = 0; return; }
  2031. X    forekill(c2-cs,0);
  2032. X    vichgflag = 0;
  2033. X}
  2034. X
  2035. Xvoid vichange() /**/
  2036. X{
  2037. Xint c2;
  2038. X
  2039. X    startvichange(1);
  2040. X    if ((c2 = getvirange(1)) == -1)
  2041. X        { vichgflag = 0; return; }
  2042. X    forekill(c2-cs,0);
  2043. X    bindtab = mainbindtab;
  2044. X    undoing = 0;
  2045. X}
  2046. X
  2047. Xvoid visubstitute() /**/
  2048. X{
  2049. X    if (mult < 0) return;
  2050. X    if (findeol()-cs < mult) mult = findeol()-cs;
  2051. X    if (mult) {
  2052. X        foredel(mult);
  2053. X        startvitext(1);
  2054. X    }
  2055. X}
  2056. X
  2057. Xvoid vichangeeol() /**/
  2058. X{
  2059. X    killline();
  2060. X    startvitext(1);
  2061. X}
  2062. X
  2063. Xvoid vichangewholeline() /**/
  2064. X{
  2065. Xint cq;
  2066. X
  2067. X    findline(&cs,&cq);
  2068. X    foredel(cq-cs);
  2069. X    startvitext(1);
  2070. X}
  2071. X
  2072. Xvoid viyank() /**/
  2073. X{
  2074. Xint c2;
  2075. X
  2076. X    if ((c2 = getvirange(0)) == -1) return;
  2077. X    cut(cs,c2-cs,0);
  2078. X}
  2079. X
  2080. Xvoid viyankeol() /**/
  2081. X{
  2082. Xint x = findeol();
  2083. X
  2084. X    if (x == cs)
  2085. X        feep();
  2086. X    else
  2087. X        cut(cs,x-cs,0);
  2088. X}
  2089. X
  2090. Xvoid vireplace() /**/
  2091. X{
  2092. X    startvitext(0);
  2093. X}
  2094. X
  2095. Xvoid vireplacechars() /**/
  2096. X{
  2097. Xint ch;
  2098. X
  2099. X    if (mult < 0) return;
  2100. X    if (mult+cs > ll) {
  2101. X        feep();
  2102. X        return;
  2103. X    }
  2104. X    startvichange(1);
  2105. X    if (ch = vigetkey()) while (mult--) line[cs++] = ch;
  2106. X    vichgflag = 0;
  2107. X    cs--;
  2108. X}
  2109. X
  2110. Xvoid vicmdmode() /**/
  2111. X{
  2112. X    bindtab = altbindtab;
  2113. X    if (cs) cs--;
  2114. X    undoing = 1;
  2115. X    if (vichgflag) vichgflag = 0;
  2116. X}
  2117. X
  2118. Xvoid viopenlinebelow() /**/
  2119. X{
  2120. X    cs = findeol();
  2121. X    spaceinline(1);
  2122. X    line[cs++] = '\n';
  2123. X    startvitext(1);
  2124. X}
  2125. X
  2126. Xvoid viopenlineabove() /**/
  2127. X{
  2128. X    cs = findbol();
  2129. X    spaceinline(1);
  2130. X    line[cs] = '\n';
  2131. X    startvitext(1);
  2132. X}
  2133. X
  2134. Xvoid vioperswapcase() /**/
  2135. X{
  2136. Xint c2;
  2137. X
  2138. X    if ((c2 = getvirange(0)) == -1)
  2139. X        return;
  2140. X    while (cs < c2)
  2141. X        {
  2142. X        int ch = line[cs];
  2143. X
  2144. X        if (islower(ch))
  2145. X            ch = tuupper(ch);
  2146. X        else if (isupper(ch))
  2147. X            ch = tulower(ch);
  2148. X        line[cs++] = ch;
  2149. X        }
  2150. X}
  2151. X
  2152. Xvoid virepeatchange() /**/
  2153. X{
  2154. X    if (!vichgbuf || bindtab == mainbindtab || vichgflag) feep();
  2155. X    else ungetkeys(vichgbuf,vichgbufptr);
  2156. X}
  2157. X
  2158. Xvoid viindent() /**/
  2159. X{
  2160. Xint c2,endcs,t0,rmult;
  2161. X
  2162. X    if (mult < 0) { mult = -mult; viunindent(); return; }
  2163. X    rmult = mult;
  2164. X    if ((c2 = getvirange(0)) == -1)
  2165. X        return;
  2166. X    if (cs != findbol()) { feep(); return; }
  2167. X    endcs = cs+rmult;
  2168. X    while (cs < c2) {
  2169. X        spaceinline(rmult);
  2170. X        for (t0 = 0; t0 != rmult; t0++) line[cs++] = '\t';
  2171. X        cs = findeol()+1;
  2172. X    }
  2173. X    cs = endcs;
  2174. X}
  2175. X
  2176. Xvoid viunindent() /**/
  2177. X{
  2178. Xint c2,endcs,t0,rmult;
  2179. X
  2180. X    rmult = mult;
  2181. X    if (mult < 0) { mult = -mult; viindent(); return; }
  2182. X    if ((c2 = getvirange(0)) == -1)
  2183. X        return;
  2184. X    if (cs != findbol()) { feep(); return; }
  2185. X    endcs = cs;
  2186. X    while (cs < c2) {
  2187. X        for (t0 = 0; t0 != rmult && line[cs] == '\t'; t0++) foredel(1);
  2188. X        cs = findeol()+1;
  2189. X    }
  2190. X    cs = endcs;
  2191. X}
  2192. SHAR_EOF
  2193. chmod 0644 zsh2.2/src/zle_vi.c ||
  2194. echo 'restore of zsh2.2/src/zle_vi.c failed'
  2195. Wc_c="`wc -c < 'zsh2.2/src/zle_vi.c'`"
  2196. test 4793 -eq "$Wc_c" ||
  2197.     echo 'zsh2.2/src/zle_vi.c: original size 4793, current size' "$Wc_c"
  2198. rm -f _shar_wnt_.tmp
  2199. fi
  2200. # ============= zsh2.2/src/ztype.h ==============
  2201. if test -f 'zsh2.2/src/ztype.h' -a X"$1" != X"-c"; then
  2202.     echo 'x - skipping zsh2.2/src/ztype.h (File already exists)'
  2203.     rm -f _shar_wnt_.tmp
  2204. else
  2205. > _shar_wnt_.tmp
  2206. echo 'x - extracting zsh2.2/src/ztype.h (Text)'
  2207. sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/src/ztype.h' &&
  2208. X/*
  2209. X *
  2210. X * ztype.h - character classification macros
  2211. X *
  2212. X * This file is part of zsh, the Z shell.
  2213. X *
  2214. X * This software is Copyright 1992 by Paul Falstad
  2215. X *
  2216. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  2217. X * use this software as long as: there is no monetary profit gained
  2218. X * specifically from the use or reproduction of this software, it is not
  2219. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  2220. X * included prominently in any copy made. 
  2221. X *
  2222. X * The author make no claims as to the fitness or correctness of this software
  2223. X * for any use whatsoever, and it is provided as is. Any use of this software
  2224. X * is at the user's own risk. 
  2225. X *
  2226. X */
  2227. X
  2228. X#define IDIGIT  1
  2229. X#define IALNUM  2
  2230. X#define IBLANK  4
  2231. X#define INBLANK 8
  2232. X#define ITOK    16
  2233. X#define ISEP    32
  2234. X#define IALPHA  64
  2235. X#define IIDENT  128
  2236. X#define IUSER   256
  2237. X#define ICNTRL  512
  2238. X#define IWORD     1024
  2239. X#define ISPECIAL 2048
  2240. X#define _icom(X,Y) (typtab[(int) (unsigned char) (X)] & Y)
  2241. X#define idigit(X) _icom(X,IDIGIT)
  2242. X#define ialnum(X) _icom(X,IALNUM)
  2243. X#define iblank(X) _icom(X,IBLANK)        /* blank, not including \n */
  2244. X#define inblank(X) _icom(X,INBLANK)        /* blank or \n */
  2245. X#define itok(X) _icom(X,ITOK)
  2246. X#define isep(X) _icom(X,ISEP)
  2247. X#define ialpha(X) _icom(X,IALPHA)
  2248. X#define iident(X) _icom(X,IIDENT)
  2249. X#define iuser(X) _icom(X,IUSER)            /* username char */
  2250. X#define icntrl(X) _icom(X,ICNTRL)
  2251. X#define iword(X) _icom(X,IWORD)
  2252. X#define ispecial(X) _icom(X,ISPECIAL)
  2253. X
  2254. XEXTERN short int typtab[256];
  2255. X
  2256. SHAR_EOF
  2257. chmod 0644 zsh2.2/src/ztype.h ||
  2258. echo 'restore of zsh2.2/src/ztype.h failed'
  2259. Wc_c="`wc -c < 'zsh2.2/src/ztype.h'`"
  2260. test 1486 -eq "$Wc_c" ||
  2261.     echo 'zsh2.2/src/ztype.h: original size 1486, current size' "$Wc_c"
  2262. rm -f _shar_wnt_.tmp
  2263. fi
  2264. # ============= zsh2.2/src/zle_tricky.c ==============
  2265. if test -f 'zsh2.2/src/zle_tricky.c' -a X"$1" != X"-c"; then
  2266.     echo 'x - skipping zsh2.2/src/zle_tricky.c (File already exists)'
  2267.     rm -f _shar_wnt_.tmp
  2268. else
  2269. > _shar_wnt_.tmp
  2270. echo 'x - extracting zsh2.2/src/zle_tricky.c (Text)'
  2271. sed 's/^X//' << 'SHAR_EOF' > 'zsh2.2/src/zle_tricky.c' &&
  2272. X/*
  2273. X *
  2274. X * zle_tricky.c - expansion and completion
  2275. X *
  2276. X * This file is part of zsh, the Z shell.
  2277. X *
  2278. X * This software is Copyright 1992 by Paul Falstad
  2279. X *
  2280. X * Permission is hereby granted to copy, reproduce, redistribute or otherwise
  2281. X * use this software as long as: there is no monetary profit gained
  2282. X * specifically from the use or reproduction of this software, it is not
  2283. X * sold, rented, traded or otherwise marketed, and this copyright notice is
  2284. X * included prominently in any copy made. 
  2285. X *
  2286. X * The author make no claims as to the fitness or correctness of this software
  2287. X * for any use whatsoever, and it is provided as is. Any use of this software
  2288. X * is at the user's own risk. 
  2289. X *
  2290. X */
  2291. X
  2292. X#define ZLE
  2293. X#include "zsh.h"
  2294. X#ifdef __hpux
  2295. X#include <ndir.h>
  2296. X#else
  2297. X#ifdef SYSV
  2298. X#define direct dirent
  2299. X#else
  2300. X#include <sys/dir.h>
  2301. X#endif
  2302. X#endif
  2303. X#include    <pwd.h>
  2304. X
  2305. Xstatic int we,wb,usemenu,useglob;
  2306. X
  2307. Xstatic int menub,menue,menuw;
  2308. SHAR_EOF
  2309. true || echo 'restore of zsh2.2/src/zle_tricky.c failed'
  2310. fi
  2311. echo 'End of zsh2.2 part 14'
  2312. echo 'File zsh2.2/src/zle_tricky.c is continued in part 15'
  2313. echo 15 > _shar_seq_.tmp
  2314. exit 0
  2315.  
  2316. exit 0 # Just in case...
  2317.